package com.will.txj.aj.server.client.fallback;

import com.will.txj.aj.server.client.WYServerClient;
import com.will.txj.common.result.R;
import com.will.txj.common.result.RC;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Component;

/**
 * @author: wen-yi;
 * @date: 2021/12/8 14:11;
 * @Description: hystrix熔断处理
 */
@Slf4j
@Component
public class WYFallbackClientFactory implements FallbackFactory<WYServerClient> {
    @Override
    public WYServerClient create(Throwable throwable) {
        log.warn("wy-server 调用程序出现了异常: {}",throwable.toString());
        return new WYServerClient() {
            @Override
            public R hello() {
                return R.fail(RC.CONNECT_FAIL);
            }

            @Override
            public R role() {
                return R.fail(RC.CONNECT_FAIL);
            }

            @Override
            public R permission() {
                return R.fail(RC.CONNECT_FAIL);
            }
        };
    }
}
